package 链表题目;

import 链表题目.model.ListNode;

import java.util.ArrayDeque;

class 回文链表 {

    public boolean isPalindrome(ListNode head) {
        ArrayDeque<ListNode> deque = new ArrayDeque<>();
        while (head != null) {
            deque.push(head);
            head = head.next;
        }
        int len = deque.size();
        while (!deque.isEmpty()) {
            ListNode l = deque.pollFirst();
            ListNode r = deque.pollLast();
            if (r == null && len != 1) {
                return false;
            }
            if (r == null) {
                return true;
            }
            if (l.val != r.val) return false;
        }
        return true;
    }
}
